package reference;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class UserMa {
	public UserMa() throws IOException{
		this.UserFolder = new File(System.getProperty("user.dir")+File.separator+"local");
		if(this.UserFolder.isDirectory()==false){
			System.out.println("MinerWeibo\\local does not exist.");
			return;
		}
		this.initiaNormalUsers();
		this.initiaAbnormalUsers();
	}
	
	private void initiaNormalUsers() throws IOException{
		this.normalUsers = new ArrayList<String>();
		File f = new File(this.UserFolder,"normal.txt");
		if(f.exists()==false){
			System.out.println("normal.txt does not exit, initialize normalUsers failed.");
			return;
		}
		BufferedReader br = new BufferedReader(new FileReader(f));
		String str = null;
		while((str=br.readLine())!=null){
			this.normalUsers.add(str);
		}
		br.close();
		System.out.println("initialize "+this.normalUsers.size()+" normal users.");
	}
	
	private void initiaAbnormalUsers() throws IOException{
		this.abnormalUsers = new ArrayList<String>();
		File f = new File(this.UserFolder,"abnormal.txt");
		if(f.exists()==false){
			System.out.println("abnormal.txt does not exit, initialize normalUsers failed.");
			return;
		}
		BufferedReader br = new BufferedReader(new FileReader(f));
		String str = null;
		while((str=br.readLine())!=null)
			this.abnormalUsers.add(str);
		br.close();
		System.out.println("initialize "+this.abnormalUsers.size()+" abnormal users.");
	}
	
	public List<String> getNormal(){
		return this.normalUsers;
	}
	
	public List<String> getAbnormal(){
		return this.abnormalUsers;
	}
	
	public List<String> getUser(){
		List<String> users = new ArrayList<String>();
		users.addAll(this.normalUsers);
		users.addAll(this.abnormalUsers);
		return users;
	}
	
	private File UserFolder;
	private List<String> normalUsers;
	private List<String> abnormalUsers;
}
